home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / TERMINAL / SRCS / OTHEROPT.C < prev    next >
Text File  |  1990-11-20  |  4KB  |  154 lines

  1. /*
  2.     Terminal 2.0
  3.     "OtherOptions.c"
  4. */
  5.  
  6. #ifdef THINK_C
  7. #include "MacHeaders"
  8. #endif
  9. #ifdef applec
  10. #pragma load ":(Objects):MacHeadersMPW"
  11. #pragma segment Options
  12. #endif
  13.  
  14. #include "Options.h"
  15. #include "Strings.h"
  16. #include "Utilities.h"
  17. #include "Text.h"
  18. #include "Main.h"
  19.  
  20. #define B_OK        1
  21. #define B_CANCEL    2
  22. #define E_TEXT_CR    3    /* Capture TEXT file creator */
  23. #define E_BIN_TYPE    4    /* Non-Macbinary file type */
  24. #define E_BIN_CR    5    /* ... and creator */
  25. #define E_BACKSPACE    6    /* Code for backspace key */
  26. #define E_ESCAPE    7    /* Code for ` key */
  27. #define C_BEEP        8    /* Control-G beeps */
  28. #define R_CONTROL    9    /* Control key = control */
  29. #define R_OPTION    10    /* Control key = option */
  30. #define R_COMMAND    11    /* Control key = command */
  31. #define T_CONTROL    12    /* Control key frame */
  32. #define U_CONTROL    13
  33. #define U_TITLELINE    14    /* Underline */
  34.  
  35. /* ----- Convert creator/type to string -------------------------------- */
  36.  
  37. static void ToString(long num, register Byte *str)
  38. {
  39.     str[0] = 4;
  40.     memcpy((void *)(str + 1), (void *)&num, 4);
  41. }
  42.  
  43. /* ----- Convert string to creator/type -------------------------------- */
  44.  
  45. static long FromString(register Byte *str)
  46. {
  47.     register short i;
  48.     long num;
  49.  
  50.     i = str[0];
  51.     while(i < 4)
  52.         str[++i] = ' ';
  53.     memcpy((void *)&num, (void *)(str + 1), 4);
  54.     return num;
  55. }
  56.  
  57. /* ----- Other options dialog ------------------------------------------ */
  58.  
  59. void OtherOptions(void)
  60. {
  61.     register DialogPtr dialog;
  62.     long num;
  63.     short i;
  64.     short number;
  65.     Byte str[256];
  66.  
  67.     CenterDialog('DLOG', DLOG_OTHER);
  68.     if (!(dialog = GetNewDialog(DLOG_OTHER, 0, (WindowPtr)-1L)))
  69.         return;
  70.     SetUserItem(dialog, U_CONTROL, (ProcPtr)DrawUserFrame);
  71.     SetUserItem(dialog, U_TITLELINE, (ProcPtr)DrawUserLine);
  72.     ToString(Settings.textCreator, str);
  73.     SetEText(dialog, E_TEXT_CR, str);
  74.     ToString(Settings.binType, str);
  75.     SetEText(dialog, E_BIN_TYPE, str);
  76.     ToString(Settings.binCreator, str);
  77.     SetEText(dialog, E_BIN_CR, str);
  78.     NumToString(Settings.backspace & 0x7F, str);
  79.     SetEText(dialog, E_BACKSPACE, str);
  80.     NumToString(Settings.escape & 0x7F, str);
  81.     SetEText(dialog, E_ESCAPE, str);
  82.     SelIText(dialog, E_TEXT_CR, 0, 32767);
  83.     SetCheck(dialog, C_BEEP, Settings.beep);
  84.     SetRadioButton(dialog, R_CONTROL, R_COMMAND, R_CONTROL+Settings.ctrl);
  85.     ShowWindow(dialog);
  86.     for (;;) {
  87.         ModalDialog(OutlineFilter, &number);
  88.         switch(number) {
  89.             case B_OK:
  90.                 GetEText(dialog, E_TEXT_CR, str);
  91.                 num = FromString(str);
  92.                 if (num != Settings.textCreator) {
  93.                     Settings.textCreator = num;
  94.                     Settings.dirty = TRUE;
  95.                 }
  96.                 GetEText(dialog, E_BIN_TYPE, str);
  97.                 num = FromString(str);
  98.                 if (num != Settings.binType) {
  99.                     Settings.binType = num;
  100.                     Settings.dirty = TRUE;
  101.                 }
  102.                 GetEText(dialog, E_BIN_CR, str);
  103.                 num = FromString(str);
  104.                 if (num != Settings.binCreator) {
  105.                     Settings.binCreator = num;
  106.                     Settings.dirty = TRUE;
  107.                 }
  108.                 GetEText(dialog, E_BACKSPACE, str);
  109.                 StringToNum(str, &num);
  110.                 if (num < 0 || num > 128) {
  111.                     SysBeep(1);
  112.                     SelIText(dialog, E_BACKSPACE, 0, 32767);
  113.                     break;
  114.                 }
  115.                 if (num != Settings.backspace) {
  116.                     Settings.backspace = num;
  117.                     Settings.dirty = TRUE;
  118.                 }
  119.                 GetEText(dialog, E_ESCAPE, str);
  120.                 StringToNum(str, &num);
  121.                 if (num < 0 || num > 128) {
  122.                     SysBeep(1);
  123.                     SelIText(dialog, E_ESCAPE, 0, 32767);
  124.                     break;
  125.                 }
  126.                 if (num != Settings.escape) {
  127.                     Settings.escape = num;
  128.                     Settings.dirty = TRUE;
  129.                 }
  130.                 if ((i = GetCheck(dialog, C_BEEP)) != Settings.beep) {
  131.                     Settings.beep = i;
  132.                     Settings.dirty = TRUE;
  133.                 }
  134.                 if ((i = GetRadioButton(dialog, R_CONTROL, R_COMMAND)
  135.                         - R_CONTROL) != Settings.ctrl) {
  136.                     Settings.ctrl = i;
  137.                     Settings.dirty = TRUE;
  138.                 }
  139.                 /* fall thru */
  140.             case B_CANCEL:
  141.                 DisposDialog(dialog);
  142.                 return;
  143.             case C_BEEP:
  144.                 ToggleCheckBox(dialog, number);
  145.                 break;
  146.             case R_CONTROL:
  147.             case R_OPTION:
  148.             case R_COMMAND:
  149.                 SetRadioButton(dialog, R_CONTROL, R_COMMAND, number);
  150.                 break;
  151.         }
  152.     }
  153. }
  154.